package com.hmtech.aup.util

import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit

object TokenUtils {
    private const val SA_TOKEN_KEY = "sa_token_key"
    private const val PREFS_NAME = "my_prefs"

    fun getTokenFromLocal(context: Context): String? {
        return getSharedPreferences(context).getString(SA_TOKEN_KEY, "")
    }

    fun saveTokenToLocal(context: Context, token: String) {
        getSharedPreferences(context).edit() { putString(SA_TOKEN_KEY, token) }
    }

    fun deleteTokenInLocalStorage(context: Context) {
        getSharedPreferences(context).edit() { remove(SA_TOKEN_KEY) }
    }

    private fun getSharedPreferences(context: Context): SharedPreferences {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
    }

}